package com.daiziru.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daiziru.entity.MUserCollection;
import com.daiziru.entity.MUserMessage;
import com.daiziru.service.*;
import com.daiziru.shiro.AccountProfile;
import com.daiziru.util.RedisUtil;
import org.apache.shiro.SecurityUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.ServletRequestUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 作者：無言
 * 时间：2022/12/7 11:33
 * 描述：永无BUG
 */
public class BaseController {

    @Resource
    HttpServletRequest req;

    @Autowired
    MPostService postService;

    @Autowired
    MCommentService commentService;

    @Autowired
    MUserMessageService messageService;

    @Autowired
    MUserCollectionService collectionService;
    @Autowired
    MCategoryService categoryService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    MUserService userService;

    @Autowired
    WebSocketService webSocketService;

    @Autowired
    SearchService searchService;

    //rabbitmq操作模板
    @Autowired
    AmqpTemplate amqpTemplate;

    @Autowired
    ChatService chatService;


    public Page getPage() {
        int currentPage = ServletRequestUtils.getIntParameter(req,"currentPage", 1);
        int size = ServletRequestUtils.getIntParameter(req,"size", 4);
        return new Page(currentPage, size);
    }

    /**
     * 获取当前登录用户的信息
     * @return
     */
    protected AccountProfile getProfile() {
        AccountProfile profile = (AccountProfile) SecurityUtils.getSubject().getPrincipal();
        return profile;
    }

}
